var pool = require('../db/index');
var middle = require('../middle/index');
module.exports = {
    singin: function (req) {
        console.log(req.body.username);
        return new Promise(function (resolve, reject) {
            pool.query('select * from user where username = ?', [req.body.username]).then(function (rows) {
                try {
                    console.log(rows.length);
                    if (rows.length === 0) {
                        throw new Error('账户不存在');
                    } else {
                        if (middle.encryption(req.body.username) === rows[0].password) {
                            resolve(true)
                        }else{
                            throw new Error('密码错误');
                        }
                    }
                } catch (err) {
                    reject(err);
                }
            })
        })

    }
}